// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import Routers from './router'
import App from './App'
import './assets/icon/iconfont.css'
import './iconfont/iconfont.css'
import {Cell, Group, XHeader, CellBox, Toast, ViewBox, Datetime, Card } from 'vux'
import noData from './components/noData'

Vue.component('x-header', XHeader);
Vue.component('group', Group);
Vue.component('cell', Cell);
Vue.component('cell-box', CellBox);
Vue.component('toast', Toast);
Vue.component('view-box', ViewBox);
Vue.component('datetime', Datetime);
Vue.component('card', Card);
Vue.component('no-data', noData);

Vue.use(VueRouter);

const router = new VueRouter({
    mode: 'history',
    routes: Routers
})

FastClick.attach(document.body)



Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
    if (to.name != 'login') {
        if (localStorage.getItem('loginState') == '1') {
            next();
            let loginTime = Number(localStorage.getItem('loginTime'));
            let now = new Date().getTime();
            if((loginTime + 1000 * 60 * 60 * 24 * 7) < now){
                localStorage.clear();
                next({path: '/login'});
                alert('信息已过期，请重新登陆！');
            }
        } else {
            next({path: '/login'});
            alert('检测到您还未登录,请登录后操作！');
        }
    } else {
        next()
    }
    //next();
})


/* eslint-disable no-new */
new Vue({
    router,
    render: h => h(App)
}).$mount('#app-box')

export default router
